<?xml version='1.0' encoding='UTF-8' ?>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

<f:view encoding="ISO-8859-1">
	<h:head>
		<title>Reservas</title>
		<h:outputStylesheet library="css" name="styles.css" />
		<h:outputScript library="js" name="scripts.js" />
	</h:head>
	<h:body>
		<h:form id="frmReserve" styleClass="frm"
			rendered="#{loginBean.isLogged() and loginBean.hasPermission('CadGeneral')}">
			
			<ui:include src="../templates/menu.xhtml" />
			
			<p:growl id="messages" showDetail="true" sticky="true"/>
				
			<p:panel id="panelReserva" header="Reservas">
				
				<h:outputLabel id="lblClientName" value="Cliente: "
						styleClass="outPutLabel" />
				<p:autoComplete label="Cliente" value="#{reserveBean.client}" id="acClient" completeMethod="#{clientBean.completeClients}"  
                        var="cli" itemLabel="#{cli.person.name}" itemValue="#{cli}" converter="clientConverter" forceSelection="true">
                	<p:ajax event="itemSelect" listener="#{reserveBean.acClientSelect}" update=":frmReserve:tblReservedProducts :frmReserve:messages" />
                </p:autoComplete>
                <br/>
                <br/>
                <h:panelGrid id="panelGrid" columns="2" width="100%">
                	<p:dataTable id="tblReservedProducts" var="pro" value="#{reserveBean.reservedProductList}"
                		emptyMessage="Não foi encontrado nenhum produto com a característica informada!"
                		rowKey="#{pro.prcode}"	selection="#{reserveBean.reservedProduct}" selectionMode="single">
					
						<f:facet name="header">
							<h:outputLabel value="Produtos reservados: "/>
						</f:facet>
					
						<p:column headerText="CÓDIGO">
							#{pro.barcode}
						</p:column>
						<p:column headerText="NOME">
							#{pro.name}
						</p:column>
					
						<f:facet name="footer">
							<p:commandButton id="delButton" value="Remover" onclick="confDialog.show();" icon="ui-icon-trash"/>
						</f:facet>
					
					</p:dataTable>
					
					<p:dataTable id="tblProducts" var="prod" value="#{reserveBean.productList}"
	                	selection="#{reserveBean.product}" selectionMode="single" rowKey="#{prod.barcode}">
					
						<f:facet name="header">
							<h:outputLabel value="Lista de produtos: "/>
						</f:facet>
					
						<p:column headerText="CÓDIGO">
							#{prod.barcode}
						</p:column>
						<p:column headerText="NOME">
							#{prod.name}
						</p:column>
					
						<f:facet name="footer">
							<p:commandButton id="cmdButtonRegister" value="Cadastrar" actionListener="#{reserveBean.onRegisterClick}"
								update=":frmReserve:tblReservedProducts :frmReserve:messages" icon="ui-icon-disk"/>
						</f:facet>
					
					</p:dataTable>
                </h:panelGrid>
			</p:panel>
			
			<p:confirmDialog id="confirmDialog" message="Você tem certeza que quer desfazer essa reserva?"
				header="Desfazer reserva" severity="alert" widgetVar="confDialog">
				<p:commandButton id="deleteButton" value="Sim" oncomplete="confDialog.hide();" actionListener="#{reserveBean.onDeleteClick}" update=":frmReserve:messages :frmReserve:tblReservedProducts"/>
                <p:commandButton id="cancelButton" value="Cancelar" onclick="confDialog.hide();" type="button" />
            </p:confirmDialog>
			
		</h:form>
		<h:form	rendered="#{!loginBean.isLogged() or !loginBean.hasPermission('CadGeneral')}">
			<h1 align="center">
				<h:outputText value="Acesso não autorizado a esta página!" />
			</h1>
			<h1 align="center">
				<h:graphicImage value="#{resource['images/general/forbidden.png']}" />
			</h1>
		</h:form>
		<ui:include src="../templates/footer.xhtml" />
	</h:body>
</f:view>
</html>